package com.lzh.shijicloudstack.utils;

import com.lzh.shijicloudstack.model.PageModel;
import org.springframework.util.StringUtils;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MyTools {

    /**
     * 将排序对象Map格式转成SQL语句的排序方式
     *
     * @param map List<String>
     * @return String/null
     * @author lym 2018-07-28
     */
    public static String changeSortMapIntoString(List<String> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map) {
            result.append(key.substring(1));
            if ("0".equals(key.substring(0, 1))) {
                //表示升序
                result.append(" asc,");
            } else {
                //表示降序
                result.append(" desc,");
            }
        }
        result.delete(result.length() - 1, result.length());
        return result.toString();
    }

    /**
     * 将排序对象Map格式转成SQL语句的排序方式——用户列表
     *
     * @param map List<String>
     * @return String/null
     * @author ycx 2020/8/25
     */
    public static String changeSortMapIntoStringForEndUserList(List<String> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map) {
            if ("capacity".equals(key.substring(1).toLowerCase())
                    || "stc_power".equals(key.substring(1).toLowerCase())) {
                result.append("b." + key.substring(1) + " + 0");
            } else if ("module_type".equals(key.substring(1).toLowerCase())
                    || "grid_type".equals(key.substring(1).toLowerCase())) {
                result.append("b." + key.substring(1));
            } else {
                result.append(key.substring(1));
            }
            if ("0".equals(key.substring(0, 1))) {
                //表示升序
                result.append(" asc,");
            } else {
                //表示降序
                result.append(" desc,");
            }
        }
        result.delete(result.length() - 1, result.length());
        return result.toString();
    }

    /**
     * 将排序对象Map格式转成SQL语句的排序方式——模拟项目列表
     *
     * @param map List<String>
     * @return String/null
     * @author xwt 2022/8/25
     */
    public static String changeSortMapIntoStringForProjectList(List<String> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map) {
            result.append("a." + key.substring(1));

            if ("0".equals(key.substring(0, 1))) {
                //表示升序
                result.append(" asc,");
            } else {
                //表示降序
                result.append(" desc,");
            }
        }
        result.delete(result.length() - 1, result.length());
        return result.toString();
    }

    /**
     * 将排序对象Map格式转成SQL语句的排序方式——组件规格列表
     *
     * @param map List<String>
     * @return String/null
     * @author xwt 2022/8/25
     */
    public static String changeSortMapIntoStringForProjectModuleSpecList(List<String> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map) {
            String field = key.substring(1);
            if ("country_cn".equals(field)
                    || "country_en".equals(field)
                    || "isAssociated".equals(field)) {
                //不做处理
            } else {
                result.append("a.");
            }

            result.append(field);

            if ("0".equals(key.substring(0, 1))) {
                //表示升序
                result.append(" asc,");
            } else {
                //表示降序
                result.append(" desc,");
            }
        }
        result.delete(result.length() - 1, result.length());
        return result.toString();
    }

    /**
     * 将排序对象Map格式转成SQL语句的排序方式——方案列表
     *
     * @param map List<String>
     * @return String/null
     * @author xwt 2023/10/16
     */
    public static String changeSortMapIntoStringForProjectSchemeList(List<String> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map) {
            result.append("a." + key.substring(1));

            if ("0".equals(key.substring(0, 1))) {
                //表示升序
                result.append(" asc,");
            } else {
                //表示降序
                result.append(" desc,");
            }
        }
        result.delete(result.length() - 1, result.length());
        return result.toString();
    }

    /**
     * 将排序对象Map格式转成SQL语句的排序方式——组件
     *
     * @param map List<String>
     * @return java.lang.String
     * @author ycx
     * @date 2020/7/30
     */
    public static String changeSortMapIntoStringForPanel(List<String> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map) {
            result.append(key.substring(1));
            if (key.toLowerCase().contains("stcpower")) {
                result.append(" + 0");
            }
            if ("0".equals(key.substring(0, 1))) {
                //表示升序
                result.append(" asc,");
            } else {
                //表示降序
                result.append(" desc,");
            }
        }
        result.delete(result.length() - 1, result.length());
        return result.toString();
    }

    /**
     * 将排序对象Map格式转成SQL语句的排序方式——用户列表
     *
     * @param map List<String>
     * @return String/null
     * @author ycx 2020/8/25
     */
    public static String changeSortMapIntoStringForRemoteDcInfoList(List<String> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map) {
            if (key.substring(1).toLowerCase().contains("inverter_dev_id")) {
                result.append("inverter_no");
            } else {
                result.append(key.substring(1));
            }
            if ("0".equals(key.substring(0, 1))) {
                //表示升序
                result.append(" asc,");
            } else {
                //表示降序
                result.append(" desc,");
            }
        }
        result.delete(result.length() - 1, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句——终端用户
     *
     * @param map Map<String,Object>
     * @return String
     * @author ycx
     * @date 2020-04-02
     */
    public static String changeQueryMapIntoStringForEndUserList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.toLowerCase().contains("userid")) {
                result.append("a.integratorid");
            } else if (key.toLowerCase().contains("share_flag")) {
                result.append("b.share_flag");
            } else if (key.toLowerCase().contains("username")) {
                result.append("a.username");
            } else if (key.toLowerCase().contains("firstname")) {
                result.append("a.firstname");
            } else if (key.toLowerCase().contains("ecu_dev_id")) {
                if ("1".equals(key.substring(key.length() - 1))) {
                    //表示是精确查询
                    result.append("( e.ecu_dev_id ");
                    result.append(" = ");
                    result.append("'").append(map.get(key)).append("'");
                    result.append(" or ");
                    result.append("e.parent_ecu_dev_id");
                    result.append(" = ");
                    result.append("'").append(map.get(key)).append("'");
                    result.append(") ");
                    result.append(" and");
                } else {
                    //表示是模糊查询
                    result.append("( e.ecu_dev_id ");
                    result.append(" like ");
                    result.append("'%").append(map.get(key)).append("%'");
                    result.append(" or ");
                    result.append("e.parent_ecu_dev_id");
                    result.append(" like ");
                    result.append("'%").append(map.get(key)).append("%'");
                    result.append(") ");
                    result.append(" and");
                }
                continue;
            } else if (key.toLowerCase().contains("inverter_dev_id")) {
                result.append("f.inverter_dev_id");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句——模拟项目
     *
     * @param map Map<String,Object>
     * @return String
     * @author ycx
     * @date 2020-04-02
     */
    public static String changeQueryMapIntoStringForProjectList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            result.append("a." + key.substring(0, key.length() - 1));
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句——组件模板
     *
     * @param map Map<String,Object>
     * @return String
     * @author ycx
     * @date 2020-04-02
     */
    public static String changeQueryMapIntoStringForProjectModuleSpecList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" a.");
            result.append(key, 0, key.length() - 1);
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句——方案
     *
     * @param map Map<String,Object>
     * @return String
     * @author ycx
     * @date 2020-04-02
     */
    public static String changeQueryMapIntoStringForProjectSchemeList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            result.append("a." + key.substring(0, key.length() - 1));
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句——用户名申请
     *
     * @param map Map<String,Object>
     * @return String
     * @author ycx
     * @date 2020/7/23
     */
    public static String changeQueryMapIntoStringForModifyUsernameApplicationList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.toLowerCase().contains("application_datetime")) {
                result.append("date_format(a.application_datetime, '%Y-%m-%d')");
            } else if (key.toLowerCase().contains("check_datetime")) {
                result.append("date_format(a.check_datetime, '%Y-%m-%d')");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }

        return result.length() > 0 ? result.delete(result.length() - 3, result.length()).toString() : null;
    }

    /**
     * 将查询对象Map格式转成SQL语句——终端用户——分销商
     *
     * @param map Map<String,Object>
     * @return String
     * @author ycx
     * @date 2020-04-21
     */
    public static String changeQueryMapIntoStringForEndUserListOfInstaller(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.toLowerCase().contains("country")) {
                result.append("b.country");
            } else if (key.toLowerCase().contains("state_code")) {
                result.append("b.state_code");
            } else if (key.toLowerCase().contains("share_flag")) {
                result.append("b.share_flag");
            } else if (key.toLowerCase().contains("username")) {
                result.append("a.username");
            } else if (key.toLowerCase().contains("firstname")) {
                result.append("a.firstname");
            } else if (key.toLowerCase().contains("true_name")) {
                result.append("a.true_name");
            } else if (key.toLowerCase().contains("module_type") || key.toLowerCase().contains("stc_power") || key.toLowerCase().contains("grid_type")) {
                result.append("b.").append(key, 0, key.length() - 1);
            } else if (key.toLowerCase().contains("installername")) {
                result.append("g.username");
            } else if (key.toLowerCase().contains("ecu_dev_id")) {
                if ("1".equals(key.substring(key.length() - 1))) {
                    //表示是精确查询
                    result.append("( f.ecu_dev_id ");
                    result.append(" = ");
                    result.append("'").append(map.get(key)).append("'");
                    result.append(" or ");
                    result.append("f.parent_ecu_dev_id");
                    result.append(" = ");
                    result.append("'").append(map.get(key)).append("'");
                    result.append(") ");
                    result.append(" and");
                } else {
                    //表示是模糊查询
                    result.append("( f.ecu_dev_id ");
                    result.append(" like ");
                    result.append("'%").append(map.get(key)).append("%'");
                    result.append(" or ");
                    result.append("f.parent_ecu_dev_id");
                    result.append(" like ");
                    result.append("'%").append(map.get(key)).append("%'");
                    result.append(") ");
                    result.append(" and");
                }
                continue;
            } else if (key.toLowerCase().contains("inverter_dev_id")) {
                result.append("f.inverter_dev_id");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句——终端用户——分销商
     *
     * @param map Map<String,Object>
     * @return String
     * @author ycx
     * @date 2020-04-21
     */
    public static String changeQueryMapIntoStringForEndUserListOfInstallerForGen4(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.toLowerCase().contains("userid")) {
                if ("1".equals(key.substring(key.length() - 1))) {
                    //表示是精确查询
                    result.append("( f.parentid ");
                    result.append(" = ");
                    result.append("'").append(map.get(key)).append("'");
                    result.append(" or ");
                    result.append("a.integratorid");
                    result.append(" = ");
                    result.append("'").append(map.get(key)).append("'");
                    result.append(") ");
                    result.append(" and");
                }
                continue;
            } else if (key.toLowerCase().contains("country")) {
                result.append("b.country");
            } else if (key.toLowerCase().contains("share_flag")) {
                result.append("b.share_flag");
            } else if (key.toLowerCase().contains("username")) {
                result.append("a.username");
            } else if (key.toLowerCase().contains("firstname")) {
                result.append("a.firstname");
            } else if (key.toLowerCase().contains("ecu_dev_id")) {
                if ("1".equals(key.substring(key.length() - 1))) {
                    //表示是精确查询
                    result.append("( f.ecu_dev_id ");
                    result.append(" = ");
                    result.append("'").append(map.get(key)).append("'");
                    result.append(" or ");
                    result.append("f.share_ecu_id");
                    result.append(" = ");
                    result.append("'").append(map.get(key)).append("'");
                    result.append(") ");
                    result.append(" and");
                } else {
                    //表示是模糊查询
                    result.append("( f.ecu_dev_id ");
                    result.append(" like ");
                    result.append("'%").append(map.get(key)).append("%'");
                    result.append(" or ");
                    result.append("f.share_ecu_id");
                    result.append(" like ");
                    result.append("'%").append(map.get(key)).append("%'");
                    result.append(") ");
                    result.append(" and");
                }
                continue;
            } else if (key.toLowerCase().contains("inverter_dev_id")) {
                result.append("f.inverter_dev_id");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }


    /**
     * 将查询对象Map格式转成SQL语句的排序方式——安装商
     *
     * @param map Map<String,Object>
     * @return String
     * @author ycx
     * @date 2020-04-02
     */
    public static String changeQueryMapIntoStringForInstallerList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.toLowerCase().contains("username")) {
                result.append("a.username");
            } else if (key.toLowerCase().contains("parentid")) {
                result.append("a.parentid");
            } else if (key.toLowerCase().contains("country")) {
                result.append("b.country");
            } else if (key.toLowerCase().contains("state_code")) {
                result.append("b.state_code");
            } else if (key.toLowerCase().contains("email")) {
                result.append("a.email");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式——视图
     *
     * @param map Map<String,Object>
     * @return String
     * @author ycx
     * @date 2020-04-02
     */
    public static String changeQueryMapIntoStringForViewList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.toLowerCase().contains("user_id")) {
                result.append("a.user_id");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象List格式转成SQL语句的排序方式——未完成用户列表
     *
     * @param list :
     * @return java.lang.String
     * @author ycx
     * @date 2021/10/18
     */
    public static String changeFilterListIntoStringForIncompleteUserList(List<String> list) {
        StringBuilder result = new StringBuilder();
        for (String map : list) {
            result.append(" (");
            for (String key : map.split("/")) {
                result.append(" b.");
                result.append(key.split("&")[0]);
                result.append(" ");
                result.append("=");
                result.append(" ");
                result.append("'").append(key.split("&")[1]).append("'");
                result.append(" ");
                result.append("or");
            }
            result.delete(result.length() - 2, result.length());
            result.append(") ");
            result.append("and");
        }

        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象List格式转成SQL语句的排序方式
     *
     * @param list :
     * @return java.lang.String
     * @author ycx
     * @date 2023/7/13
     */
    public static String changeFilterListIntoString(List<String> list) {
        StringBuilder result = new StringBuilder();
        for (String map : list) {
            result.append(" (");
            for (String key : map.split("/")) {
                result.append(" ");
                result.append(key.split("&")[0]);
                result.append(" ");
                result.append("=");
                result.append(" ");
                result.append("'").append(key.split("&")[1]).append("'");
                result.append(" ");
                result.append("or");
            }
            result.delete(result.length() - 2, result.length());
            result.append(") ");
            result.append("and");
        }

        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象List格式转成SQL语句的排序方式——终端用户
     *
     * @param list Map<String,Object>
     * @return String
     * @author ycx 2020-04-02
     */
    public static String changeFilterListIntoStringForEndUserList(List<String> list) {
        StringBuilder result = new StringBuilder();
        for (String map : list) {
            result.append(" (");
            for (String key : map.split("/")) {
                result.append(" e.");
                result.append(key.split("&")[0]);
                result.append(" ");
                result.append("=");
                result.append(" ");
                result.append("'").append(key.split("&")[1]).append("'");
                result.append(" ");
                result.append("or");
            }
            result.delete(result.length() - 2, result.length());
            result.append(") ");
            result.append("and");
        }

        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象List格式转成SQL语句的排序方式——模拟项目
     *
     * @param list Map<String,Object>
     * @return String
     * @author ycx 2020-04-02
     */
    public static String changeFilterListIntoStringForProjectList(List<String> list) {
        StringBuilder result = new StringBuilder();
        for (String map : list) {
            result.append(" (");
            for (String key : map.split("/")) {
                result.append(" ");
                result.append("a." + key.split("&")[0]);
                result.append(" ");
                result.append("=");
                result.append(" ");
                result.append("'").append(key.split("&")[1]).append("'");
                result.append(" ");
                result.append("or");
            }
            result.delete(result.length() - 2, result.length());
            result.append(") ");
            result.append("and");
        }

        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象List格式转成SQL语句的排序方式——组件模板
     *
     * @param list Map<String,Object>
     * @return String
     * @author ycx 2020-04-02
     */
    public static String changeFilterListIntoStringForProjectModuleSpecList(List<String> list) {
        StringBuilder result = new StringBuilder();
        for (String map : list) {
            result.append(" (");
            for (String key : map.split("/")) {
                result.append(" a.");
                result.append(key.split("&")[0]);
                result.append(" ");
                result.append("=");
                result.append(" ");
                result.append("'").append(key.split("&")[1]).append("'");
                result.append(" ");
                result.append("or");
            }
            result.delete(result.length() - 2, result.length());
            result.append(") ");
            result.append("and");
        }

        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象List格式转成SQL语句的排序方式——方案
     *
     * @param list Map<String,Object>
     * @return String
     * @author ycx 2020-04-02
     */
    public static String changeFilterListIntoStringForProjectSchemeList(List<String> list) {
        StringBuilder result = new StringBuilder();
        for (String map : list) {
            result.append(" (");
            for (String key : map.split("/")) {
                result.append(" ");
                result.append("a." + key.split("&")[0]);
                result.append(" ");
                result.append("=");
                result.append(" ");
                result.append("'").append(key.split("&")[1]).append("'");
                result.append(" ");
                result.append("or");
            }
            result.delete(result.length() - 2, result.length());
            result.append(") ");
            result.append("and");
        }

        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式——通用
     *
     * @param map :
     * @return java.lang.String
     * @author ycx
     * @date 2020/6/28
     */
    public static String changeQueryMapIntoString(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            result.append(key, 0, key.length() - 1);
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式——通用
     *
     * @param map :
     * @return java.lang.String
     * @author ycx
     * @date 2020/6/28
     */
    public static String changeQueryMapIntoStringForAlarmSystemList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.toLowerCase().contains("username")) {
                result.append("a.username");
            } else if (key.toLowerCase().contains("country")) {
                result.append("a.country");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式——诊断单
     *
     * @param map :
     * @return java.lang.String
     * @author ycx
     * @date 2020/7/25
     */
    public static String changeQueryMapIntoStringForDiagnoseList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.toLowerCase().contains("createusername")) {
                result.append("f.username");
            } else if (key.toLowerCase().contains("pointusername")) {
                result.append("i.username");
            } else if (key.toLowerCase().contains("username")) {
                result.append("a.username");
            } else if (key.toLowerCase().contains("firstname")) {
                result.append("a.firstname");
            } else if (key.toLowerCase().contains("lastname")) {
                result.append("a.lastname");
            } else if (key.toLowerCase().contains("status")) {
                result.append("b.status");
            } else if (key.toLowerCase().contains("createdate")) {
                result.append("date_format(b.createDate, '%Y-%m-%d')");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式——组件
     *
     * @param map :
     * @return java.lang.String
     * @author ycx
     * @date 2020/7/2
     */
    public static String changeQueryMapIntoStringForPanel(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.toLowerCase().contains("username")) {
                result.append("b.username");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式
     *
     * @param map
     * @return
     * @author ycx 2020-04-02
     */
    public static String changeCompareMapIntoString(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            result.append(key, 1, key.length());
            result.append(" ");
            if ("0".equals(key.substring(0, 1))) {
                //0表示是=
                result.append("=");
                result.append(" ");
                result.append("'" + map.get(key) + "'");
            } else if ("1".equals(key.substring(0, 1))) {
                //1表示是>
                result.append(">");
                result.append(" ");
                result.append("'" + map.get(key) + "'");
            } else if ("2".equals(key.substring(0, 1))) {
                //2表示是>=
                result.append(">=");
                result.append(" ");
                result.append("'" + map.get(key) + "'");
            } else if ("3".equals(key.substring(0, 1))) {
                //3表示是<
                result.append("<");
                result.append(" ");
                result.append("'" + map.get(key) + "'");
            } else if ("4".equals(key.substring(0, 1))) {
                //4表示是<=
                result.append("<=");
                result.append(" ");
                result.append("'" + map.get(key) + "'");
            } else {
                //5表示是!=
                result.append("!=");
                result.append(" ");
                result.append("'" + map.get(key) + "'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式——ECU列表
     *
     * @param map Map<String,Object>
     * @return String
     * @author ycx
     * @date 2020-04-14
     */
    public static String changeQueryMapIntoStringForEcuInfoList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.toLowerCase().contains("userid")) {
                result.append("a.user_id");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(map.get(key)).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(map.get(key)).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式——DC列表
     *
     * @param map Map<String,Object>
     * @return String
     * @author ycx
     * @date 2020-04-14
     */
    public static String changeQueryMapIntoStringForDcInfoList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.toLowerCase().contains("ecuid")) {
                result.append("b.id");
            } else if (key.toLowerCase().contains("inverter_dev_id")) {
                result.append("a.inverter_dev_id");
            } else if (key.toLowerCase().contains("username")) {
                result.append("c.username");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式——上报的DC列表
     *
     * @param map :
     * @return java.lang.String
     * @author ycx
     * @date 2020/10/19
     */
    public static String changeQueryMapIntoStringForRemoteDcInfoList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.toLowerCase().contains("inverter_dev_id")) {
                result.append("inverter_no");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式——DC设备的保护参数
     *
     * @param dcType :
     * @param map    :
     * @return java.lang.String
     * @author ycx
     * @date 2021/2/25
     */
    public static String changeQueryMapIntoStringForDcProtectionData(String dcType, Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            if ("0".equals(dcType) && "gfdi_ird0".equals(key)) {
                if ("1".equals(map.get(key).toString())) {
                    result.append(" (gfdi_ird_A!='0' or gfdi_ird_B!='0') and");
                } else {
                    result.append(" (gfdi_ird_A='0' and gfdi_ird_B='0') and");
                }
            } else if ("0".equals(dcType) && "other0".equals(key)) {
                if ("1".equals(map.get(key).toString())) {
                    result.append(" (tmProtection!='0' or cgfProtection !='0' or hvProtection!='0' or (eppeomdone='0' and controlState!='0')) and");
                } else {
                    result.append(" (tmProtection='0' and cgfProtection='0' and hvProtection='0' and (eppeomdone!='0' or controlState='0')) and");
                }
            } else if ("1".equals(dcType) && "other0".equals(key)) {
                if ("1".equals(map.get(key).toString())) {
                    result.append(" (tmProtection!='0' or cgfProtection !='0' or (eppeomdone='0' and controlState!='0')) and");
                } else {
                    result.append(" (tmProtection='0' and cgfProtection='0' and (eppeomdone!='0' or controlState='0')) and");
                }
            } else if ("2".equals(dcType) && "other0".equals(key)) {
                if ("1".equals(map.get(key).toString())) {
                    result.append(" (tmProtection!='0'" +
                            " or relayProtect!='0'" +
                            " or cgfProtection!='0'" +
                            " or acfRange_2!='00'" +
                            " or event1!='0'" +
                            " or event2!='0'" +
                            " or event3!='0'" +
                            " or event4!='0'" +
                            " or event5!='0'" +
                            " or event6!='0'" +
                            " or (event7!='0' and event7!='')" +
                            " or (event8!='0' and event8!='')" +
                            " or (eppeomdone='0' and controlState!='0')) and");
                } else {
                    result.append(" (tmProtection='0'" +
                            " and relayProtect='0'" +
                            " and cgfProtection='0'" +
                            " and acfRange_2='00'" +
                            " and event1='0'" +
                            " and event2='0'" +
                            " and event3='0'" +
                            " and event4='0'" +
                            " and event5='0'" +
                            " and event6='0'" +
                            " and (event7='0' or event7='')" +
                            " and (event8='0' or event8='')" +
                            " and (eppeomdone!='0' or controlState='0')) and");
                }
            } else if ("3".equals(dcType) && "acAVRange_40".equals(key)) {
                if ("1".equals(map.get(key).toString())) {
                    result.append("(event1!='0'" +
                            "or event2!='0') and");
                } else {
                    result.append("(event1='0'" +
                            "and event2='0') and");
                }
            } else if ("3".equals(dcType) && "other0".equals(key)) {
                if ("1".equals(map.get(key).toString())) {
                    result.append(" (tmProtection!='0'" +
                            "or cgfProtection!='0'" +
                            "or acAVRange_1!='00'" +
                            "or relayProtect!='00'" +
                            "or acfRange_2!= '00'" +
                            "or event3!='0'" +
                            "or event4!='0'" +
                            "or event5!='0'" +
                            "or event6!='0'" +
                            "or event7!='0'" +
                            "or event8!='0'" +
                            "or (eppeomdone='0' and controlState!='0')) and");
                } else {
                    result.append(" (tmProtection='0'" +
                            "and cgfProtection='0'" +
                            "and acAVRange_1='00'" +
                            "and relayProtect='00'" +
                            "and acfRange_2= '00'" +
                            "and event3='0'" +
                            "and event4='0'" +
                            "and event5='0'" +
                            "and event6='0'" +
                            "and event7='0'" +
                            "and event8='0'" +
                            "and (eppeomdone!='0' or controlState='0')) and");
                }
            } else if (("14".equals(dcType) || ("15".equals(dcType))) && "acAVRange0".equals(key)) {
                if ("01".equals(map.get(key).toString())) {
                    result.append(" (acAVRange_1!='00' or acAVRange_2!='00' or acAVRange_3!='00' or acAVRange_4!='00') and");
                } else {
                    result.append(" (acAVRange_1='00' and acAVRange_2='00' or acAVRange_3='00' and acAVRange_4='00') and");
                }
            } else if (("14".equals(dcType) || ("15".equals(dcType))) && "acfRange0".equals(key)) {
                if ("01".equals(map.get(key).toString())) {
                    result.append(" (acfRange_1!='00' or acfRange_2!='00') and");
                } else {
                    result.append(" (acfRange_1='00' and acfRange_2='00') and");
                }
            } else if (("14".equals(dcType) || ("15".equals(dcType))) && "other0".equals(key)) {
                if ("1".equals(map.get(key).toString())) {
                    result.append(" (tmProtection!='0'" +
                            "or relayProtect!='0'" +
                            "or cgfProtection!='0'" +
                            "or event1!='0'" +
                            "or event2!='0'" +
                            "or event3!='0'" +
                            "or event4!='0'" +
                            "or event5!='0'" +
                            "or (event7!='0' and event7!='')" +
                            "or (event8!='0' and event8!='')" +
                            "or varistorPro!='0'" +
                            "or dcInjection!='0'" +
                            "or cpProtection_1!='0'" +
                            "or cpProtection_2!='0'" +
                            ") and");
                } else {
                    result.append(" (tmProtection='0'" +
                            "and relayProtect='0'" +
                            "and cgfProtection='0'" +
                            "and event1='0'" +
                            "and event2='0'" +
                            "and event3='0'" +
                            "and event4='0'" +
                            "and event5='0'" +
                            "and (event7='0' or event7='')" +
                            "and (event8='0' or event8='')" +
                            "and varistorPro='0'" +
                            "and dcInjection='0'" +
                            "and cpProtection_1='0'" +
                            "and cpProtection_2='0'" +
                            ") and");
                }
            } else if (("16".equals(dcType) || "17".equals(dcType)) && "acABVRange0".equals(key)) {
                if ("01".equals(map.get(key).toString())) {
                    result.append(" (acABVRange_1 != '00' or acABVRange_2!='00' or acABVRange_3!='00' or acABVRange_4!='00') and");
                } else {
                    result.append(" (acABVRange_1 = '00' and acABVRange_2='00' and acABVRange_3='00' and acABVRange_4='00') and");
                }
            } else if (("16".equals(dcType) || "17".equals(dcType)) && "acBCVRange0".equals(key)) {
                if ("01".equals(map.get(key).toString())) {
                    result.append(" (acBCVRange_1 != '00' or acBCVRange_2!='00' or acBCVRange_3!='00' or acBCVRange_4!='00') and");
                } else {
                    result.append(" (acBCVRange_1 = '00' and acBCVRange_2='00' and acBCVRange_3='00' and acBCVRange_4='00') and");
                }
            } else if (("16".equals(dcType) || "17".equals(dcType)) && "acCAVRange0".equals(key)) {
                if ("01".equals(map.get(key).toString())) {
                    result.append(" (acCAVRange_1 != '00' or acCAVRange_2!='00' or acCAVRange_3!='00' or acCAVRange_4!='00') and");
                } else {
                    result.append(" (acCAVRange_1 = '00' and acCAVRange_2='00' and acCAVRange_3='00' and acCAVRange_4='00') and");
                }
            } else if (("16".equals(dcType) || "17".equals(dcType)) && "acfRange0".equals(key)) {
                if ("01".equals(map.get(key).toString())) {
                    result.append(" (acfRange_1 != '00' or acfRange_2 != '00') and");
                } else {
                    result.append(" (acfRange_1 = '00' and acfRange_2 = '00') and");
                }
            } else if (("16".equals(dcType) || "17".equals(dcType)) && "other0".equals(key)) {
                if ("1".equals(map.get(key).toString())) {
                    result.append(" (tmProtection!='0'" +
                            "or relayProtect!='0'" +
                            "or cgfProtection!='0'" +
                            "or event1!='0'" +
                            "or event2!='0'" +
                            "or event3!='0'" +
                            "or event4!='0'" +
                            "or event5!='0'" +
                            "or (event7!='0' and event7!='')" +
                            "or (event8!='0' and event8!='')" +
                            "or varistorPro!='0'" +
                            "or dcInjection!='0'" +
                            "or cpProtection_1!='0'" +
                            "or cpProtection_2!='0'" +
                            ") and");
                } else {
                    result.append(" (tmProtection='0'" +
                            "and relayProtect='0'" +
                            "and cgfProtection='0'" +
                            "and event1='0'" +
                            "and event2='0'" +
                            "and event3='0'" +
                            "and event4='0'" +
                            "and event5='0'" +
                            "and (event7='0' or event7='')" +
                            "and (event8='0' or event8='')" +
                            "and varistorPro='0'" +
                            "and dcInjection='0'" +
                            "and cpProtection_1='0'" +
                            "and cpProtection_2='0'" +
                            ") and");
                }
            } else {
                result.append(" ");
                result.append(key, 0, key.length() - 1);
                result.append(" ");
                if ("1".equals(key.substring(key.length() - 1))) {
                    //表示是精确查询
                    result.append("=");
                    result.append(" ");
                    result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
                } else {
                    //表示是模糊查询
                    result.append("like");
                    result.append(" ");
                    result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
                }
                result.append(" ");
                result.append("and");
            }
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 检测Map对象是否为空
     *
     * @param map List<String>
     * @return boolean
     * @author lym 2018-07-28
     */
    public static boolean checkMapStringIntegerNullOrNot(List<String> map) {
        return map != null && map.size() > 0;
    }


    /**
     * 检测Map对象是否为空
     *
     * @param map Map<String,Object>
     * @return boolean
     * @author lym 2018-07-28
     */
    public static boolean checkMapStringObjectNullOrNot(Map<String, Object> map) {
        return map != null && !map.isEmpty();
    }

    /**
     * 检测List对象是否为空
     *
     * @param list List<Map<String, String>>
     * @return boolean
     * @author ycx 2020-04-02
     */
    public static boolean checkListStringObjectNullOrNot(List<String> list) {
        return list != null && !list.isEmpty();
    }


    /**
     * 保存文件
     *
     * @param img      图片字节流
     * @param path     路径
     * @param fileName 文件名
     * @author lym 2018-07-30
     */
    public static void SaveFile(String path, byte[] img, String fileName) {
        try {
            File file = new File(path + "/" + fileName);
            FileOutputStream fops = new FileOutputStream(file);
            fops.write(img);
            fops.flush();
            fops.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 删除文件
     *
     * @param path     路径
     * @param filename 文件名
     * @author lym 2018-07-30
     */
    public static void DeleteFile(String path, String filename) {
        File file = new File(path + "/" + filename);
        if (file.exists()) {
            /* 如果文件存在 就删除   */
            file.delete();
        }
    }


    /**
     * 处理翻页对象
     *
     * @param pageModel PageModel
     * @return PageModel
     * @author lym 2018-07-31
     */
    public static PageModel dealWithPageModel(PageModel pageModel) {
        //恶意操作，万一页码在总页码之后 那就只能是最后一页
        int pageCount = (int) Math.ceil((double) pageModel.getTotal() / pageModel.getPageSize());
        if (pageCount < pageModel.getPageNow()) {
            pageModel.setPageNow(pageCount);
        }
        //获取当前需要查询那一页的数据
        //记录开始的第一套
        int startCount = (pageModel.getPageNow() - 1) * pageModel.getPageSize();
        pageModel.setStartCount(startCount);
        pageModel.setPageCount(pageCount);
        return pageModel;
    }

    /**
     * 创建翻页查询对象
     *
     * @param pageModel PageModel
     * @param language  语言
     * @return Map<String, Object>
     */
    public static Map<String, Object> createQueryMapForPageModel(PageModel pageModel, String language) {
        //查询对象
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startCount", pageModel.getStartCount());
        queryMap.put("pageSize", pageModel.getPageSize());
        if (language != null) {
            queryMap.put("language", language);
        }
        if (checkMapStringIntegerNullOrNot(pageModel.getSort())) {
            queryMap.put("sort", changeSortMapIntoString(pageModel.getSort()));
        }
        return queryMap;
    }

    /**
     * 创建翻页查询对象——用户列表
     *
     * @param pageModel PageModel
     * @param language  语言
     * @return Map<String, Object>
     * @author ycx 2020/8/25
     */
    public static Map<String, Object> createQueryMapForPageModelForEndUserList(PageModel pageModel, String language) {
        //查询对象
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startCount", pageModel.getStartCount());
        queryMap.put("pageSize", pageModel.getPageSize());
        if (language != null) {
            queryMap.put("language", language);
        }
        if (checkMapStringIntegerNullOrNot(pageModel.getSort())) {
            queryMap.put("sort", changeSortMapIntoStringForEndUserList(pageModel.getSort()));
        }
        return queryMap;
    }

    /**
     * 创建翻页查询对象——模拟项目列表
     *
     * @param pageModel PageModel
     * @param language  语言
     * @return Map<String, Object>
     * @author ycx 2020/8/25
     */
    public static Map<String, Object> createQueryMapForPageModelForProjectList(PageModel pageModel, String language) {
        //查询对象
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startCount", pageModel.getStartCount());
        queryMap.put("pageSize", pageModel.getPageSize());
        if (language != null) {
            queryMap.put("language", language);
        }
        if (checkMapStringIntegerNullOrNot(pageModel.getSort())) {
            queryMap.put("sort", changeSortMapIntoStringForProjectList(pageModel.getSort()));
        }
        return queryMap;
    }

    /**
     * 创建翻页查询对象——组件模板
     *
     * @param pageModel PageModel
     * @param language  语言
     * @return Map<String, Object>
     * @author ycx 2020/8/25
     */
    public static Map<String, Object> createQueryMapForPageModelForProjectModuleSpecList(PageModel pageModel, String language) {
        //查询对象
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startCount", pageModel.getStartCount());
        queryMap.put("pageSize", pageModel.getPageSize());
        if (language != null) {
            queryMap.put("language", language);
        }
        if (checkMapStringIntegerNullOrNot(pageModel.getSort())) {
            queryMap.put("sort", changeSortMapIntoStringForProjectModuleSpecList(pageModel.getSort()));
        }
        return queryMap;
    }

    /**
     * 创建翻页查询对象——方案列表
     *
     * @param pageModel PageModel
     * @param language  语言
     * @return Map<String, Object>
     * @author ycx 2020/8/25
     */
    public static Map<String, Object> createQueryMapForPageModelForProjectSchemeList(PageModel pageModel, String language) {
        //查询对象
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startCount", pageModel.getStartCount());
        queryMap.put("pageSize", pageModel.getPageSize());
        if (language != null) {
            queryMap.put("language", language);
        }
        if (checkMapStringIntegerNullOrNot(pageModel.getSort())) {
            queryMap.put("sort", changeSortMapIntoStringForProjectSchemeList(pageModel.getSort()));
        }
        return queryMap;
    }

    /**
     * 创建翻页查询对象——组件
     *
     * @param pageModel PageModel
     * @param language  语言
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author ycx
     * @date 2020/7/30
     */
    public static Map<String, Object> createQueryMapForPageModelForPanel(PageModel pageModel, String language) {
        //查询对象
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startCount", pageModel.getStartCount());
        queryMap.put("pageSize", pageModel.getPageSize());
        if (language != null) {
            queryMap.put("language", language);
        }
        if (checkMapStringIntegerNullOrNot(pageModel.getSort())) {
            queryMap.put("sort", changeSortMapIntoStringForPanel(pageModel.getSort()));
        }
        return queryMap;
    }

    /**
     * 将视图详细信息转变成为一个String 简配版本
     *
     * @param list List<Map<String,Object>>
     * @return String/null
     * @author lym  2018-08-27
     */
    public static String changeViewDetailInfoIntoSimpleString(List<Map<String, Object>> list) {
        StringBuilder result = new StringBuilder();
        for (Map<String, Object> info : list) {
            result.append((String) info.get("dc_infoId"));
            result.append((String) info.get("dc_devId"));
            result.append((String) info.get("channel"));
            result.append(String.format("%04d", Integer.parseInt((String) info.get("xposition"))));
            result.append(String.format("%04d", Integer.parseInt((String) info.get("yposition"))));
            result.append((int) info.get("panel_angle"));
        }
        return result.toString();
    }


    /**
     * 将List<Map<String,Object>> 转变成为 Map<String,List<String>>
     *
     * @param list List<Map<String,Object>>
     * @param key  Map里面的key
     *             DC 设备识别号+DC 设备序列号+DC设备通道号+ 子串号3位+标志（0分配；1未分配）
     *             总共：20+12+1+3+1 = 37位
     * @return Map<String, List < String>>
     * @author lym  2018-08-13
     */
    public static Map<String, List<String>> changeListMapIntoMapStringList(List<Map<String, Object>> list, String key) {
        Map<String, List<String>> result = new HashMap<>();
        for (Map<String, Object> map : list) {
            String field = (String) map.get(key);
            if (result.get(field) == null) {
                result.put((String) map.get(key), new ArrayList<String>());
            }
            StringBuilder child = new StringBuilder();
            child.append((String) map.get("dc_infoId"));
            child.append((String) map.get("dc_devId"));
            child.append((String) map.get("channel"));
            child.append(String.format("%03d", (Integer) map.get("substring_num")));
            if (map.get("open_flag") != null) {
                child.append("1");
            } else {
                child.append("0");
            }
            result.get((String) map.get(key)).add(child.toString());
        }
        return result;
    }

    /**
     * 昱能DC设备数据补点
     *
     * @param ECUFlag ECU标志
     * @param DCFlag  DC标志轴
     * @param energy  能量轴
     * @return List<String>
     * @author lym  2018-08-13
     */
    public static List<String> CheckPointsWithECUFlagAndDCFlag(List<Integer> ECUFlag, List<Integer> DCFlag, List<String> energy) {
        List<String> result = new ArrayList<>();
        int j = 0;
        for (int i = 0; i < energy.size(); i++) {
            if (ECUFlag.get(i) == 1) {
                if ((DCFlag.get(i) != null) && (DCFlag.get(i) == 1)) {
                    result.add(energy.get(i));
                } else {
                    if (j > 0) {
                        result.add(result.get(j - 1));
                    } else {
                        result.add("0");
                    }
                }
                j++;
            }
        }
        return result;
    }


    /**
     * 昱能DC设备数据补点
     *
     * @param ECUFlag ECU标志
     * @param energy  能量轴
     * @return List<String>
     * @author lym  2018-08-13
     */
    public static List<String> CheckPointsWithECUFlagAndDCFlag2(List<Integer> ECUFlag, List<String> energy) {
        List<String> result = new ArrayList<String>();
        for (int i = 0; i < ECUFlag.size(); i++) {
            if (ECUFlag.get(i) == 1) {
                result.add(energy.get(i));
            }
        }
        return result;
    }


    /**
     * 初始化列表
     *
     * @param size 列表的长度
     * @return List<String>
     * @author lym  2018-08-20
     */
    public static List<String> initList(int size) {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            list.add(null);
        }
        return list;
    }


    /**
     * 初始化列表
     *
     * @param size 列表的长度
     * @return List<Integer>
     * @author lym  2019-07-03
     */
    public static List<Integer> initIntegerList(int size) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            list.add(null);
        }
        return list;
    }


    /**
     * 初始化列表
     *
     * @param size 列表的长度
     * @return List<Double>
     * @author lym  2018-08-23
     */
    public static List<Double> initDoubleList(int size) {
        List<Double> list = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            list.add(null);
        }
        return list;
    }


    /**
     * 初始化列表
     *
     * @param size 列表的长度
     * @return List<Float>
     * @author lym  2018-09-21
     */
    public static List<Float> initFloatList(int size) {
        List<Float> list = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            list.add(null);
        }
        return list;
    }


    /**
     * 优化器/关断器/逆变器  在Redis中的该天的实时数据能力统计后缀都是不一样的
     * 500/1000: channel+"I" 或者   "O/A/B/C"+channel
     * 1200/600: "I"+channel 或者  "O"
     * OPT: "E"+channel 或者  "OE
     *
     * @param channel   通道
     * @param pointType 点表类型
     * @return String/null
     * @author lym  2018-08-21
     */
    public static String changeChannelIntoRedisFormat(String channel, String pointType) {
        switch (pointType) {
            case "1"://YC200
                return "I";
            case "6": //OPT
            case "10":
            case "12":
                if ("O".equals(channel)) {
                    return "OE";
                } else {
                    return "E" + channel;
                }
            case "7": //600
            case "14": //DS3
            case "8": //QS1
            case "13": //QS1A
            case "15": //DS3D
                if ("O".equals(channel)) {
                    return "O";
                } else {
                    return "I" + channel;
                }
            case "4": //1000
                if ("A".equals(channel) || "B".equals(channel) || "C".equals(channel)) {
                    return channel + "O";
                } else {
                    return channel + "I";
                }
            case "16": //QT2
            case "17": //QT2D
                if ("A".equals(channel) || "B".equals(channel) || "C".equals(channel)) {
                    return "O" + channel;
                } else {
                    return "I" + channel;
                }
            case "2": //500
            default:
                if ("O".equals(channel)) {
                    return "O";
                } else {
                    return channel + "I";
                }
        }
    }


    /**
     * 过滤操作ECU的功率曲线
     *
     * @param FList 标志轴
     * @param power 功率轴
     * @return List<String>
     * @author lym 2018-08-22
     */
    public static List<String> checkECUPower(List<Integer> FList, List<String> power) {
        if (power == null) {
            return null;
        }
        List<String> result = new ArrayList<>();
        int i = 0;
        for (Integer flag : FList) {
            if (flag == 1) {
                result.add(power.get(i));
            }
            i++;
        }
        return result;
    }


    /**
     * 将String列表转换成为Double列表
     *
     * @param list 列表
     * @return List<Double>
     * @author lym 2018-08-24
     */
    public static List<Double> changeListStringIntoListDouble(List<String> list) {
        List<Double> result = initDoubleList(list.size());
        int i = 0;
        for (String num : list) {
            if (num != null) {
                result.set(i, Double.valueOf(num));
            }
            i++;
        }
        return result;
    }


    /**
     * 处理数据，视图获取每一块组件的一段时间每天的发电量，目前都是固定30天的，
     * 由于数据比较大， 所以讲数据组合成为String，再传递出去
     *
     * @param list Map<String,List<String>>
     * @param size 目前都是固定30天的，
     * @return String/null
     * @author lym 2018-08-30
     */
    public static String changeDailyEnergyIntoStringForAutoViewAndManualView(Map<String, List<String>> list, int size) {
        StringBuilder result = new StringBuilder();
        List<String> totalList = initList(size);
        for (String uidC : list.keySet()) {
            List<String> energyList = list.get(uidC);
            int i = 0;
            result.append(uidC);
            result.append("/");
            for (String energy : energyList) {
                totalList.set(i, CalculateTools.PlusTwoStringParam(totalList.get(i), energy));
                i++;
                if (energy != null) {
                    result.append(energy);
                } else {
                    result.append(0);
                }
                result.append(",");
            }
            result.delete(result.length() - 1, result.length());
            result.append("&");
        }
        //汇总数据
        result.append("E/");
        for (String energy : totalList) {
            if (energy != null) {
                result.append(energy);
            } else {
                result.append(0);
            }
            result.append(",");
        }
        result.delete(result.length() - 1, result.length());
        return result.toString();
    }

    /**
     * 变换时间轴，时间轴中的时间是  HH:mm:ss 变成  HH:mm
     *
     * @param timeList List<String>
     * @return List<String>
     * @author lym 2019-03-27
     */
    public static List<String> changeTimeFromHHmmssToHHmm(List<String> timeList) {
        for (int i = 0; i < timeList.size(); i++) {
            timeList.set(i, timeList.get(i).substring(0, 5));
        }
        return timeList;
    }


    /**
     * 处理数据，组串逆变器下面每一块DC设备的发电数据
     * 由于数据比较大， 所以讲数据组合成为String，再传递出去
     *
     * @param devList   逆变器列表
     * @param energyMap 发电量
     * @return String/null
     * @author lym 2018-11-13
     */
    public static String changeDayEnergyIntoStringForEachDCBelowDevice(List<String> devList, Map<String, String> energyMap) {
        StringBuilder result = new StringBuilder();
        for (String uidCM : devList) {
            result.append(uidCM);
            result.append("/");
            String uidC = uidCM.substring(0, 13);
            if (energyMap.get(uidC) != null) {
                result.append(energyMap.get(uidC));
            }
            result.append("&");
        }
        result.delete(result.length() - 1, result.length());
        return result.toString();
    }

    /**
     * 处理数据，根据传入的工单的Map对象中的 operate_code -本步代号操作, operate_user_level -操作者userLevel, pass_flag -通过标记
     * 来生成 status -工单状态, next_operate_code -下一步代号操作, next_operate_user_level -下一步操作者userLevel,
     *
     * @param maintenanceInfoMap 工单的Map对象
     * @return Map<String, Object>
     * @author ycx 2019-05-14
     */
    public static Map<String, Object> generateMaintenanceInfoMap(Map<String, Object> maintenanceInfoMap) {
        if (maintenanceInfoMap.get("operate_user_level") != null && !"".equals(maintenanceInfoMap.get("operate_user_level").toString())
                && maintenanceInfoMap.get("operate_code") != null && !"".equals(maintenanceInfoMap.get("operate_code").toString())
                && maintenanceInfoMap.get("pass_flag") != null && !"".equals(maintenanceInfoMap.get("pass_flag").toString())) {
            if ("0".equals(maintenanceInfoMap.get("operate_user_level").toString()) && "4".equals(maintenanceInfoMap.get("pass_flag").toString())) {
                maintenanceInfoMap.put("next_operate_user_level", "0");
                maintenanceInfoMap.put("next_operate_code", "6");
                maintenanceInfoMap.put("status", "8");
                maintenanceInfoMap.put("open_flag", "3");
                maintenanceInfoMap.put("close_reason", "2");
                maintenanceInfoMap.put("close_date", "1");
                maintenanceInfoMap.put("close_userId", "1");
            } else {
                String code = maintenanceInfoMap.get("operate_user_level").toString() + maintenanceInfoMap.get("operate_code").toString() + maintenanceInfoMap.get("pass_flag").toString();
                switch (code) {
                    case "201":
                        maintenanceInfoMap.put("next_operate_user_level", "1");
                        maintenanceInfoMap.put("next_operate_code", "7");
                        maintenanceInfoMap.put("status", "2");
                        break;
                    case "170":
                        maintenanceInfoMap.put("next_operate_user_level", "2");
                        maintenanceInfoMap.put("next_operate_code", "0");
                        maintenanceInfoMap.put("status", "0");
                        break;
                    case "171":
                        maintenanceInfoMap.put("next_operate_user_level", "0");
                        maintenanceInfoMap.put("next_operate_code", "1");
                        maintenanceInfoMap.put("status", "1");
                        break;
                    case "173":
                        maintenanceInfoMap.put("next_operate_user_level", "0");
                        maintenanceInfoMap.put("next_operate_code", "6");
                        maintenanceInfoMap.put("status", "8");
                        maintenanceInfoMap.put("open_flag", "2");
                        maintenanceInfoMap.put("close_reason", "1");
                        maintenanceInfoMap.put("close_date", "1");
                        maintenanceInfoMap.put("close_userId", "1");
                        break;
                    case "010":
                        maintenanceInfoMap.put("next_operate_user_level", "1");
                        maintenanceInfoMap.put("next_operate_code", "7");
                        maintenanceInfoMap.put("status", "2");
                        maintenanceInfoMap.remove("release_date");
                        maintenanceInfoMap.remove("release_userId");
                        break;
                    case "011":
                        maintenanceInfoMap.put("next_operate_user_level", "1");
                        maintenanceInfoMap.put("next_operate_code", "2");
                        maintenanceInfoMap.put("status", "2");
                        maintenanceInfoMap.put("release_date", "1");
                        maintenanceInfoMap.put("release_userId", "1");
                        break;
                    case "012":
                        maintenanceInfoMap.put("next_operate_user_level", "0");
                        maintenanceInfoMap.put("next_operate_code", "6");
                        maintenanceInfoMap.put("status", "8");
                        maintenanceInfoMap.put("open_flag", "2");
                        maintenanceInfoMap.put("close_reason", "0");
                        maintenanceInfoMap.put("close_date", "1");
                        maintenanceInfoMap.put("close_userId", "1");
                        break;
                    case "120":
                        maintenanceInfoMap.put("next_operate_user_level", "0");
                        maintenanceInfoMap.put("next_operate_code", "1");
                        maintenanceInfoMap.put("status", "1");
                        maintenanceInfoMap.put("return", "1");
                        break;
                    case "121":
                        maintenanceInfoMap.put("next_operate_user_level", "2");
                        maintenanceInfoMap.put("next_operate_code", "3");
                        maintenanceInfoMap.put("status", "3");
                        break;
                    case "231":
                        maintenanceInfoMap.put("next_operate_user_level", "2");
                        maintenanceInfoMap.put("next_operate_code", "4");
                        maintenanceInfoMap.put("status", "5");
                        maintenanceInfoMap.put("accept_date", 1);
                        maintenanceInfoMap.put("maintenance_userId", "1");
                        break;
                    case "230":
                        maintenanceInfoMap.put("next_operate_user_level", "2");
                        maintenanceInfoMap.put("next_operate_code", "3");
                        maintenanceInfoMap.put("status", "3");
                        maintenanceInfoMap.remove("accept_date");
                        maintenanceInfoMap.remove("maintenance_userId");
                        maintenanceInfoMap.put("recall", "1");
                        break;
                    case "150":
                        maintenanceInfoMap.put("next_operate_user_level", "2");
                        maintenanceInfoMap.put("next_operate_code", "4");
                        maintenanceInfoMap.put("status", "5");
                        break;
                    case "151":
                        maintenanceInfoMap.put("next_operate_user_level", "0");
                        maintenanceInfoMap.put("next_operate_code", "6");
                        maintenanceInfoMap.put("status", "7");
                        break;
                    case "067":
                        maintenanceInfoMap.put("next_operate_user_level", "0");
                        maintenanceInfoMap.put("next_operate_code", "6");
                        maintenanceInfoMap.put("status", "8");
                        maintenanceInfoMap.put("open_flag", "2");
                        maintenanceInfoMap.put("close_reason", "4");
                        maintenanceInfoMap.put("close_date", "1");
                        maintenanceInfoMap.put("close_userId", "1");
                        break;
                    case "065":
                        maintenanceInfoMap.put("next_operate_user_level", "0");
                        maintenanceInfoMap.put("next_operate_code", "6");
                        maintenanceInfoMap.put("status", "8");
                        maintenanceInfoMap.put("open_flag", "2");
                        maintenanceInfoMap.put("close_reason", "3");
                        maintenanceInfoMap.put("close_date", "1");
                        maintenanceInfoMap.put("close_userId", "1");
                        break;
                    case "066":
                        maintenanceInfoMap.put("next_operate_user_level", "0");
                        maintenanceInfoMap.put("next_operate_code", "6");
                        maintenanceInfoMap.put("status", "8");
                        maintenanceInfoMap.put("open_flag", "2");
                        maintenanceInfoMap.put("close_reason", "5");
                        maintenanceInfoMap.put("close_date", "1");
                        maintenanceInfoMap.put("close_userId", "1");
                        break;
                    case "060":
                        maintenanceInfoMap.put("next_operate_user_level", "1");
                        maintenanceInfoMap.put("next_operate_code", "5");
                        maintenanceInfoMap.put("status", "6");
                        break;
                    default:
                        break;
                }

            }
            return maintenanceInfoMap;
        } else {
            return null;
        }

    }

    /**
     * 将字符串转成列表
     *
     * @param string : 字符串
     * @return java.util.List<java.lang.String>
     * @author ycx
     * @date 2020/4/14
     */
    public static List<String> changeStringToList(String string) {
        List<String> list = new ArrayList<>();

        if (string != null) {
            for (int i = 0; i < string.length(); i++) {
                list.add(String.valueOf(string.charAt(i)));
            }
        } else {
            list.add(null);
        }

        return list;
    }

    /**
     * 转译查询字段中的特殊字符
     *
     * @param value : 查询字段
     * @return java.lang.String
     * @author ycx
     * @date 2020/5/25
     */
    private static String translateQueryValue(String value) {
        String result = value.replace("\\", "\\\\");
        result = result.replace("'", "\\'");
        result = result.replace("%", "\\%");
        return result.replace("_", "\\_");
    }

    /**
     * 获取ECU关联设备类别
     *
     * @param type : 逆变器组别
     * @return int :
     * @author ycx
     * @date 2020/5/28
     */
    public static int getEcuType(String type) {
        switch (Integer.parseInt(type)) {
            case 2:
                return 2;
            default:
                return 0;
        }
    }

    /**
     * 将int转换成两位的String,一位数补零
     *
     * @param num 数字
     * @author ycx 2019-07-17
     */
    public static String formatNum(int num) {
        return num >= 10 ? Integer.toString(num) : "0" + num;
    }


    public static void replaceListByStart(List<String> list1, List<String> list2, int start) {
        for (int i = 0; i < list2.size(); i++) {
            list1.set(start + i, list2.get(i));
        }
    }

    /**
     * 根据长度格式化字符串，前面补0
     *
     * @param string : 字符串
     * @param num    : 位数
     * @author ycx 2019-07-17
     */
    public static String formatStringByLength(String string, int num) {

        return Integer.toString(Integer.parseInt(string) + (int) Math.pow(10, num)).substring(1);
    }

    /**
     * 判断Ecu关联的设备类型
     *
     * @param ecuConnectDcType : Ecu关联的Dc类型
     * @param dcTypeList       : Dc类型及其相关配置信息
     * @return int
     * @author ycx
     * @date 2020/7/28
     */
    public static int getEcuType(Map<String, Object> ecuConnectDcType, List<Map<String, String>> dcTypeList) {
        if (ecuConnectDcType == null || ecuConnectDcType.isEmpty() || dcTypeList == null || dcTypeList.isEmpty()) {
            return 0;
        }
        for (Map<String, String> dcType : dcTypeList) {
            if ("2".equals(dcType.get("group"))) {
                if ((int) ecuConnectDcType.get("DC_TYPE_" + dcType.get("dc_type")) == 1) {

                    return 2;
                }
            }
        }
        return 0;
    }

    /**
     * 判断Ecu关联的设备类型
     *
     * @param ecuConnectDcType : Ecu关联的Dc类型
     * @param dcTypeList       : Dc类型及其相关配置信息
     * @return int
     * @author ycx
     * @date 2020/9/1
     */
    public static int getEcuType(String ecuConnectDcType, List<Map<String, String>> dcTypeList) {
        if (ecuConnectDcType == null || "".equals(ecuConnectDcType) || dcTypeList == null || dcTypeList.isEmpty()) {
            return 0;
        }
        for (Map<String, String> dcType : dcTypeList) {
            if (ecuConnectDcType.equals(dcType.get("dc_type"))) {
                if ("2".equals(dcType.get("group"))) {
                    return 2;
                }
                break;
            }
        }
        return 0;
    }


    /**
     * 初始化列表
     *
     * @param size 列表的长度
     * @return java.util.List<java.lang.String>
     * @author ycx
     * @date 2020/9/21
     */
    public static List<List<String>> initStringListList(int size) {
        List<List<String>> list = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            list.add(null);
        }
        return list;
    }

    /**
     * 根据ECU号码判断ECU类型
     *
     * @param ecuDevId : ECU号码
     * @return int
     * @author ycx
     * @date 2020/10/14
     */
    public static int getEcuTypeByPrefix(String ecuDevId) {
        switch (ecuDevId.substring(0, 3)) {
            case "223":
            case "224":
            case "225":
            case "217":
                //优化器
                return 2;
            default:
                //微逆
                return 0;
        }
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式——通用
     *
     * @param map :
     * @return java.lang.String
     * @author lym
     * @date 2020/10/13
     */
    public static String changeQueryMapIntoStringForAlarmECUList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.contains("ecuId")) {
                result.append("c.ecu_dev_id");
            } else {
                result.append("a.");
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }


    /**
     * 将查询对象Map格式转成SQL语句的排序方式——通用
     *
     * @param map :
     * @return java.lang.String
     * @author lym
     * @date 2020/10/19
     */
    public static String changeQueryMapIntoStringForTurnOffAlarmList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.contains("inverterId") || key.contains("ecuId")) {
                result.append("a.");
            } else {
                result.append("b.");
            }
            result.append(key, 0, key.length() - 1);
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }


    /**
     * 将查询对象Map格式转成SQL语句的排序方式——通用
     *
     * @param map :
     * @return java.lang.String
     * @author lym
     * @date 2020/10/13
     */
    public static String changeQueryMapIntoStringForAlarmUIDList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.contains("inverterId")) {
                result.append("c.inverter_dev_id");
            } else {
                result.append("a.");
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }


    /**
     * 将查询对象Map格式转成SQL语句的排序方式——通用
     *
     * @param map :
     * @return java.lang.String
     * @author lym
     * @date 2020/10/23
     */
    public static String changeQueryMapIntoStringForLow5UIDList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.contains("user_id")) {
                result.append("c.user_id");
            } else {
                result.append("a.");
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式——安装商申请列表
     *
     * @param map :
     * @return java.lang.String
     * @author ycx
     * @date 2021/6/26
     */
    public static String changeQueryMapIntoStringForIntegratorsApplicationInfoList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            result.append(" ");
            if (key.contains("installerUsername")) {
                result.append("b.username");
            } else if (key.contains("checkUsername")) {
                result.append("d.username");
            } else if (key.toLowerCase().contains("application_datetime")) {
                result.append("date_format(a.application_datetime, '%Y-%m-%d')");
            } else if (key.toLowerCase().contains("check_datetime")) {
                result.append("date_format(a.check_datetime, '%Y-%m-%d')");
            } else {
                result.append(key, 0, key.length() - 1);
            }
            result.append(" ");
            if ("1".equals(key.substring(key.length() - 1))) {
                //表示是精确查询
                result.append("=");
                result.append(" ");
                result.append("'").append(translateQueryValue(map.get(key).toString())).append("'");
            } else {
                //表示是模糊查询
                result.append("like");
                result.append(" ");
                result.append("'%").append(translateQueryValue(map.get(key).toString())).append("%'");
            }
            result.append(" ");
            result.append("and");
        }
        result.delete(result.length() - 3, result.length());
        return result.toString();
    }

    /**
     * 检查ECU可连接逆变器规则
     *
     * @param ecuDevId    : ECU号码
     * @param dcTypeCount : 连接逆变器数量
     * @return boolean
     * @author ycx
     * @date 2022/3/21
     */
    public static boolean checkEcuConnectDcRule(String ecuDevId, Map<String, Integer> dcTypeCount) {

        if (ecuDevId.startsWith("2162")) {
            if (dcTypeCount.get("1") != null || dcTypeCount.get("2") != null) {
                return false;
            }
            int count = 0;
            for (int i = 1; i <= 20; i++) {
                count += dcTypeCount.get(Integer.toString(i));
            }
            if (count > 137) {
                return false;
            }
        } else if (ecuDevId.startsWith("2160")) {
            if (dcTypeCount.get("1") != null || dcTypeCount.get("2") != null) {
                return false;
            }
            int count = 0;
            for (int i = 1; i <= 20; i++) {
                count += dcTypeCount.get(Integer.toString(i));
            }
            if (count > 130) {
                return false;
            }
        } else if (ecuDevId.startsWith("2163")) {
            if (dcTypeCount.get("1") != null || dcTypeCount.get("2") != null || dcTypeCount.get("6") != null || dcTypeCount.get("10") != null || dcTypeCount.get("12") != null) {
                return false;
            }
            int count = 0;
            count += dcTypeCount.get("3") == null ? 0 : dcTypeCount.get("3");
            count += dcTypeCount.get("4") == null ? 0 : dcTypeCount.get("4") * 2;
            count += dcTypeCount.get("7") == null ? 0 : dcTypeCount.get("7");
            count += dcTypeCount.get("8") == null ? 0 : dcTypeCount.get("8") * 2;
            count += dcTypeCount.get("13") == null ? 0 : dcTypeCount.get("13") * 2;
            count += dcTypeCount.get("14") == null ? 0 : dcTypeCount.get("14");
            count += dcTypeCount.get("15") == null ? 0 : dcTypeCount.get("15");
            count += dcTypeCount.get("16") == null ? 0 : dcTypeCount.get("16") * 2;
            count += dcTypeCount.get("16") == null ? 0 : dcTypeCount.get("17") * 2;
            if (count > 2) {
                return false;
            }
        } else {
            int count = 0;
            for (int i = 1; i <= 20; i++) {
                count += dcTypeCount.get(Integer.toString(i)) == null ? 0 : dcTypeCount.get(Integer.toString(i));
            }
            if (count > 999) {
                return false;
            }
        }

        return true;
    }

    /**
     * 根据长度将时间字符串分割为数组
     *
     * @param timeString 时间字符串 多组HHmmssHHmmss
     * @return java.lang.String[]
     * @author ycx
     * @date 2022/7/6
     */
    public static String[] splitTimeByLength(String timeString) {
        String[] timeArray = new String[timeString.length() / 12];
        for (int i = 0; i < timeString.length() / 12; i++) {
            timeArray[i] = timeString.substring(12 * i, 12 * (i + 1));
        }

        return timeArray;
    }

    /**
     * 是否支持第三方电表
     *
     * @param ecuDevId ECU号码
     * @return java.lang.String
     * @author ycx
     * @date 2023/2/9
     */
    public static boolean checkSpuortThirdMeter(String ecuDevId) {
        return (ecuDevId.startsWith("2160") || ecuDevId.startsWith("2162") || ecuDevId.startsWith("2163"));
    }

    /**
     * 是否为全null的列表
     *
     * @param list 列表
     * @return boolean
     * @author ycx
     * @date 2023/2/9
     */
    public static boolean checkAllNullList(List<String> list) {
        for (String data : list) {
            if (data != null) {
                return false;
            }
        }
        return true;
    }

    /**
     * 执行命令
     *
     * @param command : 命令
     * @return java.lang.String
     * @author ycx
     * @date 2023/9/5
     */
    public static String executeCommand(String command) {
        StringBuilder result = new StringBuilder();

        Process process = null;
        BufferedReader bufIn = null;
        BufferedReader bufError = null;

        try {
            // 执行命令, 返回一个子进程对象（命令在子进程中执行）
            process = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", command}, null, null);

            // 获取命令执行结果, 有两个结果: 正常的输出 和 错误的输出（PS: 子进程的输出就是主进程的输入）
            bufIn = new BufferedReader(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8));
            bufError = new BufferedReader(new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8));

            // 读取输出
            String line;
            while ((line = bufIn.readLine()) != null) {
                result.append(line).append('\n');
            }
            while ((line = bufError.readLine()) != null) {
                result.append(line).append('\n');
            }

            // 方法阻塞, 等待命令执行完成（成功会返回0）
            process.waitFor();
        } catch (InterruptedException | IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bufIn != null) {
                    bufIn.close();
                }
                if (bufError != null) {
                    bufError.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            // 销毁子进程
            if (process != null) {
                process.destroy();
            }
        }

        return result.toString();
    }

    /**
     * 将查询对象Map格式转成SQL语句的排序方式
     *
     * @param map :
     * @return java.lang.String
     * @author ycx
     * @date 2020/6/28
     */
    public static String changeQueryMapIntoStringStoreList(Map<String, Object> map) {
        StringBuilder result = new StringBuilder();
        for (String key : map.keySet()) {
            Object obj = map.get(key);
            if (obj == null) {
                continue;
            }
            String value = translateQueryValue(obj.toString());
            if (!StringUtils.hasText(value)) {
                continue;
            }
            result.append(" ");
            String firstChar = key.substring(key.length() - 1);
            if ("1".equals(firstChar)) {
                // 表示是精确查询
                if ("未知".equals(value) || "NULL".equals(value)) {
                    result.append("(");
                    result.append(key, 0, key.length() - 1);
                    result.append(" IS NULL OR ");
                    result.append(key, 0, key.length() - 1);
                    result.append(" = 'NULL' OR ");
                    result.append(key, 0, key.length() - 1);
                    result.append(" = ");
                    result.append("'").append(value).append("'");
                    result.append(")");
                } else {
                    result.append(key, 0, key.length() - 1);
                    result.append(" ");
                    result.append("=");
                    result.append(" ");
                    result.append("'").append(value).append("'");
                }
            } else {
                // 表示是模糊查询
                if ("未知".equals(value) || "NULL".equals(value)) {
                    result.append("(");
                    result.append(key, 0, key.length() - 1);
                    result.append(" IS NULL OR ");
                    result.append(key, 0, key.length() - 1);
                    result.append(" LIKE ");
                    result.append("'%").append(value).append("%'");
                    result.append(")");
                } else {
                    if  ("0".equals(firstChar)) {
                        // 模糊匹配
                        result.append(key, 0, key.length() - 1);
                        result.append(" LIKE ");
                        result.append("'%").append(value).append("%'");
                    } else if ("2".equals(firstChar)) {
                        // 前缀匹配
                        result.append(key, 0, key.length() - 1);
                        result.append(" LIKE ");
                        result.append("'").append(value).append("%'");
                    } else if ("3".equals(firstChar)) {
                        // 后缀匹配
                        result.append(key, 0, key.length() - 1);
                        result.append(" LIKE ");
                        result.append("'%").append(value).append("'");
                    } else {
                        // 模糊匹配
                        result.append(key, 0, key.length() - 1);
                        result.append(" LIKE ");
                        result.append("'%").append(value).append("%'");
                    }
                }
            }
            result.append(" ");
            result.append("and");
        }
        if (result.length() >= 3) {
            result.delete(result.length() - 3, result.length());
        }
        return result.toString();
    }
}
